<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <title>Agency - Responsive Flat Admin Dashboard</title>
    <meta content="Admin Dashboard" name="description" />
    <meta content="ThemeDesign" name="author" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <link rel="shortcut icon" href="${basePath}/admin/assets/images/faviicon.png">

    <link href="${basePath}/admin/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="${basePath}/admin/assets/css/icons.css" rel="stylesheet" type="text/css">
    <link href="${basePath}/admin/assets/css/style.css" rel="stylesheet" type="text/css">

</head>


<body>

<!-- Begin page -->
<div class="accountbg" style="background:none;"></div>
<div class="wrapper-page">

    <div class="card">
        <div class="card-body">

            <h3 class="text-center mt-0 m-b-15">
                <!-- <a href="index.html" class="logo logo-admin"><img src="${basePath}/admin/assets/images/logo.png" height="30" alt="logo"></a> -->
            </h3>

            <h4 class="text-muted text-center font-18"><b>后台登录</b></h4>

            <div class="p-3">
                <form class="form-horizontal m-t-20" action="/admin/login" method="post" id="loginForm" onsubmit="return false" >

                    <div class="form-group row">
                        <div class="col-12">
                            <input class="form-control" type="text" required="" placeholder="Username" name="adminName">
                        </div>
                    </div>

                    <div class="form-group row">
                        <div class="col-12">
                            <input class="form-control" type="password" required="" placeholder="Password" name="adminPassword">
                        </div>
                    </div>

                    <div class="form-group row">
                        <!-- <div class="col-12">
                            <div class="custom-control custom-checkbox">
                                <input type="checkbox" class="custom-control-input" id="customCheck1">
                                <label class="custom-control-label" for="customCheck1">Remember me</label>
                            </div>
                        </div> -->
                    </div>

                    <div class="form-group text-center row m-t-20">
                        <div class="col-12">
                            <!-- <button class="btn btn-info btn-block waves-effect waves-light" type="submit">Log In</button> -->
                            <!-- 点击跳转到主页 -->
                            <button class="btn btn-info btn-block waves-effect waves-light" type="submit" id="loginButton">登  录</button>
                        </div>
                    </div>

                    <div class="form-group m-t-10 mb-0 row">
                        <div class="col-sm-9 m-t-20">
                            <!-- <a href="pages-recoverpw.html" class="text-muted"><i class="mdi mdi-lock    "></i> Forgot your password?</a> -->
                        </div>
                        <div class="col-sm-3 m-t-20">
                            <!-- <a href="pages-register.html" class="text-muted"><i class="mdi mdi-account-circle"></i> 注 册</a> -->
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>

<script src="${basePath}/admin/assets/js/jquery-1.9.1.min.js"></script>


<script type="text/javascript">

    $(function () {
        $('#loginForm').submit(function () {
            var postData = $("#loginForm").serialize(); //序列化表单，后台可正常通过post方法获取数据
            console.log(postData)
            $.ajax({
                type: "POST",
                url: "/admin/login",
                data: postData,
                beforeSend: function() {
                    $("#loginButton").attr("disabled", true);//提交表单前的处理，防止用户多次点击【登陆】，重复提交表单
                },
                success: function(data) {
                    if (data.success) {
                        alert('登录成功');
                        window.location.href = '/admin/index';
                    } else {
                        $("#loginButton").attr("disabled", false);
                        $("#loginButton").val("登陆");
                        alert("用户或密码错误！");
                    }
                }
            });

        });

    });


</script>
<!-- jQuery  -->
<script src="${basePath}/admin/assets/js/jquery.min.js"></script>
<script src="${basePath}/admin/assets/js/popper.min.js"></script>
<script src="${basePath}/admin/assets/js/bootstrap.min.js"></script>
<script src="${basePath}/admin/assets/js/modernizr.min.js"></script>
<script src="${basePath}/admin/assets/js/detect.js"></script>
<script src="${basePath}/admin/assets/js/fastclick.js"></script>
<script src="${basePath}/admin/assets/js/jquery.slimscroll.js"></script>
<script src="${basePath}/admin/assets/js/jquery.blockUI.js"></script>
<script src="${basePath}/admin/assets/js/waves.js"></script>
<script src="${basePath}/admin/assets/js/jquery.nicescroll.js"></script>
<script src="${basePath}/admin/assets/js/jquery.scrollTo.min.js"></script>

<!-- App js -->
<script src="${basePath}/admin/assets/js/app.js"></script>

</body>
</html>